<!DOCTYPE html>












  


<html class="theme-next pisces use-motion" lang="zh-CN">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">


























<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2">

<link rel="stylesheet" href="/css/main.css?v=7.0.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/Peppa.png?v=7.0.0">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/Peppa.jpg?v=7.0.0">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/Peppa.jpg?v=7.0.0">








<script id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    version: '7.0.0',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: false,
    fastclick: false,
    lazyload: false,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>


  




  <meta name="description" content="Cayley’s formula And Prüfer sequences Cayley 公式和 Prüfer 序列 Cayley 公式公式内容In mathematics, Cayley’s formula is a result in graph theory named after Arthur Cayley.  It states that for every positive integ">
<meta name="keywords" content="ACM,Math,Graph Theory">
<meta property="og:type" content="article">
<meta property="og:title" content="Cayley&#39;s formula And Prüfer sequences">
<meta property="og:url" content="https://linxi99.gitee.io/20190217/Cayley-s-formula-And-Prufer-sequences/index.html">
<meta property="og:site_name" content="linxi&#39;s dream">
<meta property="og:description" content="Cayley’s formula And Prüfer sequences Cayley 公式和 Prüfer 序列 Cayley 公式公式内容In mathematics, Cayley’s formula is a result in graph theory named after Arthur Cayley.  It states that for every positive integ">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="https://linxi99.gitee.io/20190217/Cayley-s-formula-And-Prufer-sequences/seq.gif">
<meta property="og:image" content="https://linxi99.gitee.io/20190217/Cayley-s-formula-And-Prufer-sequences/s1.png">
<meta property="og:image" content="https://linxi99.gitee.io/20190217/Cayley-s-formula-And-Prufer-sequences/s2.png">
<meta property="og:image" content="https://linxi99.gitee.io/20190217/Cayley-s-formula-And-Prufer-sequences/s3.png">
<meta property="og:image" content="https://linxi99.gitee.io/20190217/Cayley-s-formula-And-Prufer-sequences/s4.png">
<meta property="og:image" content="https://linxi99.gitee.io/20190217/Cayley-s-formula-And-Prufer-sequences/s5.png">
<meta property="og:image" content="https://linxi99.gitee.io/20190217/Cayley-s-formula-And-Prufer-sequences/p1.png">
<meta property="og:image" content="https://linxi99.gitee.io/20190217/Cayley-s-formula-And-Prufer-sequences/p2.png">
<meta property="og:image" content="https://linxi99.gitee.io/20190217/Cayley-s-formula-And-Prufer-sequences/p3.png">
<meta property="og:image" content="https://linxi99.gitee.io/20190217/Cayley-s-formula-And-Prufer-sequences/p4.png">
<meta property="og:image" content="https://linxi99.gitee.io/20190217/Cayley-s-formula-And-Prufer-sequences/p5.png">
<meta property="og:image" content="https://linxi99.gitee.io/20190217/Cayley-s-formula-And-Prufer-sequences/p6.png">
<meta property="og:image" content="https://linxi99.gitee.io/20190217/Cayley-s-formula-And-Prufer-sequences/p7.png">
<meta property="og:image" content="https://linxi99.gitee.io/20190217/Cayley-s-formula-And-Prufer-sequences/p8.png">
<meta property="og:updated_time" content="2020-04-12T03:24:28.050Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Cayley&#39;s formula And Prüfer sequences">
<meta name="twitter:description" content="Cayley’s formula And Prüfer sequences Cayley 公式和 Prüfer 序列 Cayley 公式公式内容In mathematics, Cayley’s formula is a result in graph theory named after Arthur Cayley.  It states that for every positive integ">
<meta name="twitter:image" content="https://linxi99.gitee.io/20190217/Cayley-s-formula-And-Prufer-sequences/seq.gif">






  <link rel="canonical" href="https://linxi99.gitee.io/20190217/Cayley-s-formula-And-Prufer-sequences/">



<script id="page.configurations">
  CONFIG.page = {
    sidebar: "",
  };
</script>

  <title>Cayley's formula And Prüfer sequences | linxi's dream</title>
  






  <script>
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?b4099cd89c9f33abab06a03748dac801";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>







  <noscript>
  <style>
  .use-motion .motion-element,
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-title { opacity: initial; }

  .use-motion .logo,
  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope="" itemtype="http://schema.org/WebPage" lang="zh-CN">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope="" itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">linxi's dream</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
    
      
        <p class="site-subtitle">穷且益坚，不坠青云之志</p>
      
    
    
  </div>

  <div class="site-nav-toggle">
    <button aria-label="切换导航栏">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>



<nav class="site-nav">
  
    <ul id="menu" class="menu">
      
        
        
        
          
          <li class="menu-item menu-item-home">

    
    
    
      
    

    

    <a href="/" rel="section"><i class="menu-item-icon fa fa-fw fa-home"></i> <br>首页</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-tags">

    
    
    
      
    

    

    <a href="/tags/" rel="section"><i class="menu-item-icon fa fa-fw fa-tags"></i> <br>标签</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-categories">

    
    
    
      
    

    

    <a href="/categories/" rel="section"><i class="menu-item-icon fa fa-fw fa-th"></i> <br>分类</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-archives">

    
    
    
      
    

    

    <a href="/archives/" rel="section"><i class="menu-item-icon fa fa-fw fa-archive"></i> <br>归档</a>

  </li>

      
      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br>搜索</a>
        </li>
      
    </ul>
  

  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



  



</div>
    </header>

    


    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          
            

          
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://linxi99.gitee.io/20190217/Cayley-s-formula-And-Prufer-sequences/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="linxi">
      <meta itemprop="description" content="stay hungry, stay foolish">
      <meta itemprop="image" content="/images/star.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="linxi's dream">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Cayley's formula And Prüfer sequences

              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">

            
            
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2019-02-17 20:48:43" itemprop="dateCreated datePublished" datetime="2019-02-17T20:48:43+08:00">2019-02-17</time>
            

            
              

              
                
                <span class="post-meta-divider">|</span>
                

                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                
                  <span class="post-meta-item-text">更新于</span>
                
                <time title="修改时间：2020-04-12 11:24:28" itemprop="dateModified" datetime="2020-04-12T11:24:28+08:00">2020-04-12</time>
              
            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope="" itemtype="http://schema.org/Thing"><a href="/categories/图论一顿套模板/" itemprop="url" rel="index"><span itemprop="name">图论一顿套模板</span></a></span>

                
                
              
            </span>
          

          
            
            
              
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
            
                <span class="post-meta-item-text">评论数：</span>
                <a href="/20190217/Cayley-s-formula-And-Prufer-sequences/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count valine-comment-count" data-xid="/20190217/Cayley-s-formula-And-Prufer-sequences/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          
            <span id="/20190217/Cayley-s-formula-And-Prufer-sequences/" class="leancloud_visitors" data-flag-title="Cayley's formula And Prüfer sequences">
              <span class="post-meta-divider">|</span>
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              
                <span class="post-meta-item-text">阅读次数：</span>
              
                <span class="leancloud-visitors-count"></span>
            </span>
            <span class="post-meta-divider">|
            </span> <span title="post.wordcount">
            <span class="post-meta-item-icon">
                <i class="fa fa-file-word-o"></i>
            </span>字数： 3.3k
            </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>Cayley’s formula And Prüfer sequences</p>
<p>Cayley 公式和 Prüfer 序列</p>
<h1 id="Cayley-公式"><a href="#Cayley-公式" class="headerlink" title="Cayley 公式"></a>Cayley 公式</h1><h2 id="公式内容"><a href="#公式内容" class="headerlink" title="公式内容"></a>公式内容</h2><p>In mathematics, Cayley’s formula is a result in graph theory named after Arthur Cayley. </p>
<p>It states that for every positive integer n, the number of trees on n labeled vertices is $n^{n - 2}$ </p>
<p>The formula equivalently counts the number of spanning trees of a complete graph with labeled vertices</p>
<p> (sequence A000272 in the OEIS). </p>
<p>上述描述来自 <a href="https://en.wikipedia.org/wiki/Cayley%27s_formula#Generalizations" target="_blank" rel="noopener">维基百科</a></p>
<a id="more"></a>
<p> Cayley 公式是说：</p>
<p>对于任何正整数 $n$</p>
<p>$n$ 个节点的带标号的无根树有 $n^{n - 2}$ 个</p>
<p>还有一种等价的说法：</p>
<p>$n$ 个有标号节点的无向完全图的生成树有 $n^{n - 2}$ 棵</p>
<h2 id="解决的问题"><a href="#解决的问题" class="headerlink" title="解决的问题"></a>解决的问题</h2><p>无限制的 n 个节点的无根树（有标号）的计数问题</p>
<p>以及无向完全图（有标号）的生成树计数问题</p>
<h2 id="公式证明方式"><a href="#公式证明方式" class="headerlink" title="公式证明方式"></a>公式证明方式</h2><ol>
<li>基尔霍夫矩阵树定理</li>
<li>Prüfer 序列（下面详述）</li>
<li>Double Counting<br>$\cdots \cdots$</li>
</ol>
<h2 id="公式的推广"><a href="#公式的推广" class="headerlink" title="公式的推广"></a>公式的推广</h2><h3 id="限制特定节点的度的树的计数"><a href="#限制特定节点的度的树的计数" class="headerlink" title="限制特定节点的度的树的计数"></a>限制特定节点的度的树的计数</h3><p>限制编号为 $i$ 的点的度数是 $d_i$，则树的个数有</p>
<script type="math/tex; mode=display">\frac{(n − 2)!} {\Pi ^ {n} _ {i = 1} (d_i − 1)!}</script><h3 id="n-个节点-k-棵树的森林计数问题"><a href="#n-个节点-k-棵树的森林计数问题" class="headerlink" title="n 个节点 k 棵树的森林计数问题"></a>n 个节点 k 棵树的森林计数问题</h3><p>The following generalizes Cayley’s formula to labelled forests: </p>
<p>Let $T _ {n, k}$ be the number of labelled forests on $n$ vertices with $k$ connected components,</p>
<p>such that vertices $1, 2, 3 \cdots k$ all belong to different connected components. </p>
<p>Then $T_{n, k} = k n^{n − k - 1}$</p>
<p>令 $T _ {n, k}$ 表示有着 $n$ 个节点的 $k$ 个联通块（$k$ 棵树）的森林的种类数，使得$1, 2, 3, \cdots, k$属于不同的子树</p>
<p>根据Cayley定理，可以推导出</p>
<script type="math/tex; mode=display">T_{n, k} = k n^{n − k - 1}</script><h1 id="Prufer-序列"><a href="#Prufer-序列" class="headerlink" title="Prüfer 序列"></a>Prüfer 序列</h1><p>借鉴 <a href="http://www.matrix67.com/blog/archives/682" target="_blank" rel="noopener">Matrix67的博客</a></p>
<h2 id="序列定义"><a href="#序列定义" class="headerlink" title="序列定义"></a>序列定义</h2><p>给定一棵带标号的无根树</p>
<p>找出编号最小的叶子节点，写下与它相邻的节点的编号，然后删掉这个叶子节点</p>
<p>反复执行这个操作直到只剩两个节点为止</p>
<h2 id="序列性质"><a href="#序列性质" class="headerlink" title="序列性质"></a>序列性质</h2><p>任何一个Prüfer编码都唯一地对应了一棵无根树</p>
<p>有多少个$n - 2$位的Prüfer编码就有多少个带标号的无根树</p>
<h2 id="证明-Cayley公式"><a href="#证明-Cayley公式" class="headerlink" title="证明 Cayley公式"></a>证明 Cayley公式</h2><p><img src="/20190217/Cayley-s-formula-And-Prufer-sequences/seq.gif" alt="序列实例"></p>
<p>注意到，如果一个节点A不是叶子节点，那么它至少有两条边</p>
<p>但在上述过程结束后，整个图只剩下一条边，因此节点A的至少一个相邻节点被去掉过，节点A的编号将会在这棵树对应的Prüfer编码中出现</p>
<p>反过来，在Prüfer编码中出现过的数字显然不可能是这棵树（初始时）的叶子</p>
<p>于是我们看到，没有在Prüfer编码中出现过的数字恰好就是这棵树（初始时）的叶子节点</p>
<p>以数列 ${3, 3, 5, 2, 5, 6, 1}$为例</p>
<p><img src="/20190217/Cayley-s-formula-And-Prufer-sequences/s1.png" alt="序列实例1"></p>
<p>找出没有出现过的数字中最小的那一个（④），它就是与Prüfer编码中第一个数所标识的节点（③）相邻的叶子</p>
<p><img src="/20190217/Cayley-s-formula-And-Prufer-sequences/s2.png" alt="序列实例2"><br>接下来，我们递归地考虑后面$n - 3$位编码（别忘了编码总长是$n - 2$）：</p>
<p>找出除④以外不在后n-3位编码中的最小的数（左图的例子中是⑦），将它连接到整个编码的第2个数所对应的节点上（例子中还是③）</p>
<p><img src="/20190217/Cayley-s-formula-And-Prufer-sequences/s3.png" alt="序列实例3"></p>
<p>再接下来，找出除④和⑦以外后n-4位编码中最小的不被包含的数，做同样的处理……依次把③⑧②⑤⑥与编码中第3、4、5、6、7位所表示的节点相连</p>
<p><img src="/20190217/Cayley-s-formula-And-Prufer-sequences/s4.png" alt="序列实例4"></p>
<p>最后，我们还有①和⑨没处理过，直接把它们俩连接起来就行了</p>
<p><img src="/20190217/Cayley-s-formula-And-Prufer-sequences/s5.png" alt="序列实例5"><br>由于没处理过的节点数总比剩下的编码长度大2，因此我们总能找到一个最小的没在剩余编码中出现的数，算法总能进行下去</p>
<p>这样，任何一个Prüfer编码都唯一地对应了一棵无根树，有多少个$n - 2$位的Prüfer编码就有多少个带标号的无根树。</p>
<h2 id="Prufer编码实例"><a href="#Prufer编码实例" class="headerlink" title="Prüfer编码实例"></a>Prüfer编码实例</h2><p>In combinatorial mathematics, the Prüfer sequence (also Prüfer code or Prüfer numbers) of a labeled tree is a unique sequence associated with the tree. </p>
<p>The sequence for a tree on n vertices has length n − 2, and can be generated by a simple iterative algorithm. </p>
<p>Prüfer sequences were first used by Heinz Prüfer to prove Cayley’s formula in 1918.</p>
<p>上面描述来自<a href="https://en.wikipedia.org/wiki/Pr%C3%BCfer_sequence" target="_blank" rel="noopener">维基百科</a></p>
<p>下面借鉴 <a href="http://www.cnblogs.com/zhj5chengfeng/p/3278557.html" target="_blank" rel="noopener">JMJST博客</a></p>
<h3 id="由一棵树得到唯一的-Prufer-Sequence"><a href="#由一棵树得到唯一的-Prufer-Sequence" class="headerlink" title="由一棵树得到唯一的 Prüfer Sequence"></a>由一棵树得到唯一的 Prüfer Sequence</h3><p>假设有一颗树有 5 个节点，四条边依次为：$(1, 2), (1, 3), (2, 4), (2, 5)$，如下图所示：</p>
<p><img src="/20190217/Cayley-s-formula-And-Prufer-sequences/p1.png" alt="Prüfer实例1"><br>第 1 步，选取具有最小标号的叶子节点 3，将与它相连的点 1 作为第 1 个 Prüfer Number，并从树中删掉节点 3：</p>
<p><img src="/20190217/Cayley-s-formula-And-Prufer-sequences/p2.png" alt="Prüfer实例2"><br>第 2 步，选取最小标号的叶子节点 1，将与其相连的点 2 作为第 2 个 Prüfer Number，并从树中删掉点 1：</p>
<p><img src="/20190217/Cayley-s-formula-And-Prufer-sequences/p3.png" alt="Prüfer实例3"><br>第 3 步，选取最小标号的叶子节点 4，将与其相连的点 2 作为第 3 个 Prüfer Number，并从树中删掉点 4：</p>
<p><img src="/20190217/Cayley-s-formula-And-Prufer-sequences/p4.png" alt="Prüfer实例4"><br>最后，我们得到的 Prüfer Sequence 为：1 2 2</p>
<h3 id="由一个-Prufer-Sequence-得到一棵树"><a href="#由一个-Prufer-Sequence-得到一棵树" class="headerlink" title="由一个 Prüfer Sequence 得到一棵树"></a>由一个 Prüfer Sequence 得到一棵树</h3><p>先将所有编号为 1 到 n 的点的度赋初值为 1</p>
<p>然后加上它在 Prüfer Sequence 中出现的次数，得到每个点的度</p>
<div class="table-container">
<table>
<thead>
<tr>
<th>顶点</th>
<th>1</th>
<th>2</th>
<th>3</th>
<th>4</th>
<th>5</th>
</tr>
</thead>
<tbody>
<tr>
<td>度数</td>
<td>2</td>
<td>3</td>
<td>1</td>
<td>1</td>
<td>1</td>
</tr>
</tbody>
</table>
</div>
<p>第 1 次执行，选取最小标号度为 1 的点 3 和 Prüfer Sequence 中的第 1 个数 1 连边：</p>
<p><img src="/20190217/Cayley-s-formula-And-Prufer-sequences/p5.png" alt="Prüfer实例5"><br>将 1 和 3 的度分别减一：</p>
<div class="table-container">
<table>
<thead>
<tr>
<th>顶点</th>
<th>1</th>
<th>2</th>
<th>3</th>
<th>4</th>
<th>5</th>
</tr>
</thead>
<tbody>
<tr>
<td>度数</td>
<td>$2 \to 1$</td>
<td>3</td>
<td>$1 \to 0$</td>
<td>1</td>
<td>1</td>
</tr>
</tbody>
</table>
</div>
<p>第 2 次执行，选取最小标号度为 1 的点 1 和 Prüfer Sequence 中的第 2 个数 2 连边：</p>
<p><img src="/20190217/Cayley-s-formula-And-Prufer-sequences/p6.png" alt="Prüfer实例6"></p>
<p>将 1 和 2 的度分别减一：</p>
<div class="table-container">
<table>
<thead>
<tr>
<th>顶点</th>
<th>1</th>
<th>2</th>
<th>3</th>
<th>4</th>
<th>5</th>
</tr>
</thead>
<tbody>
<tr>
<td>度数</td>
<td>$1 \to 0$</td>
<td>$3 \to 2$</td>
<td>0</td>
<td>1</td>
<td>1</td>
</tr>
</tbody>
</table>
</div>
<p>第 3 次执行，将最小标号度为 1 的点 4 和 Prüfer Sequence 第 3 个数 2 连边：</p>
<p><img src="/20190217/Cayley-s-formula-And-Prufer-sequences/p7.png" alt="Prüfer实例7"></p>
<p>将 2 和 4 的度分别减一：</p>
<div class="table-container">
<table>
<thead>
<tr>
<th>顶点</th>
<th>1</th>
<th>2</th>
<th>3</th>
<th>4</th>
<th>5</th>
</tr>
</thead>
<tbody>
<tr>
<td>度数</td>
<td>0</td>
<td>$2 \to 1$</td>
<td>0</td>
<td>$1 \to 0$</td>
<td>1</td>
</tr>
</tbody>
</table>
</div>
<p>最后，还剩下两个点 2 和 5 的度为 1，连边：</p>
<p><img src="/20190217/Cayley-s-formula-And-Prufer-sequences/p8.png" alt="Prüfer实例8"></p>
<p>至此，一个 Prüfer Sequence 得到的树画出来了</p>
<p>由上面的步骤可知，Prüfer Sequence 和一个树唯一对应</p>
<h1 id="相关例题"><a href="#相关例题" class="headerlink" title="相关例题"></a>相关例题</h1><h2 id="BZOJ-1005-HNOI2008-明明的烦恼"><a href="#BZOJ-1005-HNOI2008-明明的烦恼" class="headerlink" title="BZOJ 1005 [HNOI2008] 明明的烦恼"></a>BZOJ 1005 [HNOI2008] 明明的烦恼</h2><h3 id="题目描述"><a href="#题目描述" class="headerlink" title="题目描述"></a>题目描述</h3><p>给出标号为 1 到 N （$0 &lt; N \le 1000$）的点，以及某些点最终的度数 $D _ i$（如果对度数不要求，则输入  $-1$）</p>
<p>允许在任意两点间连线，可产生多少棵度数满足要求的树？</p>
<h3 id="解题思路"><a href="#解题思路" class="headerlink" title="解题思路"></a>解题思路</h3><p>根据 Cayley公式的推广式一</p>
<script type="math/tex; mode=display">\frac{(n − 2)!} {\Pi ^ {n} _ {i = 1} (d_i − 1)!}</script><p>如果这道题目没有不受限制的点，那么这道问题就结束啦</p>
<p>可是题目里面有不受限制的点，我们应该如何处理呢</p>
<p>假设度数有限制的点的数量为 cnt，它们的度数为 $D_i$</p>
<p>令<script type="math/tex">sum = \sum _ {i = 1} ^ {cnt} (D_i - 1)</script></p>
<p>那么，在序列中不同的排列的总数为：</p>
<script type="math/tex; mode=display">C _ {n - 2} ^ {sum} \times \frac{sum!}{\Pi _ {i = 1} ^ {cnt}(D_i - 1)!}</script><p>而剩下的 $n - 2 - sum$ 个位置，可以随意的排列剩余的 $n - cnt$ 个点，于是，总的方案数就应该是：</p>
<script type="math/tex; mode=display">C _ {n - 2} ^ {sum} \times \frac{sum!}{\Pi _ {i = 1} ^ {cnt}(D_i - 1)!} \times (n - cnt)^{n - 2 - sum}</script><p>化简后得到：</p>
<script type="math/tex; mode=display">\frac{(n - 2)!}{(n - 2 - sum) \Pi _ {i = 1} ^ {cnt}(D_i - 1)!} \times (n - cnt)^{n - 2 - sum}</script><p>注意答案会很大，并且没有取模操作</p>
<p>所以需要用到大整数进行运算</p>
<h3 id="代码实现"><a href="#代码实现" class="headerlink" title="代码实现"></a>代码实现</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> java.math.BigInteger;</span><br><span class="line"><span class="keyword">import</span> java.util.Scanner;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Main</span> </span>&#123;</span><br><span class="line">    <span class="keyword">static</span> <span class="keyword">int</span> d[] = <span class="keyword">new</span> <span class="keyword">int</span>[<span class="number">1005</span>];</span><br><span class="line">    <span class="keyword">static</span> BigInteger fac[] = <span class="keyword">new</span> BigInteger[<span class="number">1005</span>];</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">	<span class="comment">// write your code here</span></span><br><span class="line">        Scanner in = <span class="keyword">new</span> Scanner(System.in);</span><br><span class="line">        <span class="keyword">int</span> n = in.nextInt();</span><br><span class="line">        <span class="keyword">int</span> sum = <span class="number">0</span>, cnt = <span class="number">0</span>;</span><br><span class="line">        <span class="keyword">boolean</span> f = <span class="keyword">false</span>;</span><br><span class="line">        <span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; n; ++i)&#123;</span><br><span class="line">            d[i] = in.nextInt();</span><br><span class="line">            <span class="keyword">if</span>(d[i] == <span class="number">0</span> || d[i] &gt;= n) f = <span class="keyword">true</span>;</span><br><span class="line">            <span class="keyword">if</span>(d[i] == -<span class="number">1</span>) <span class="keyword">continue</span>;</span><br><span class="line">            sum += d[i] - <span class="number">1</span>;</span><br><span class="line">            ++cnt;</span><br><span class="line">        &#125;</span><br><span class="line">        in.close();</span><br><span class="line">        <span class="keyword">if</span>(n == <span class="number">1</span>)&#123;</span><br><span class="line">            <span class="keyword">if</span>(!f) System.out.println(<span class="number">1</span>);</span><br><span class="line">            <span class="keyword">else</span> System.out.println(<span class="number">0</span>);</span><br><span class="line">            <span class="keyword">return</span> ;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span>(n == <span class="number">2</span>)&#123;</span><br><span class="line">            <span class="keyword">if</span>(f || d[<span class="number">0</span>] == <span class="number">0</span> || d[<span class="number">1</span>] == <span class="number">0</span>) System.out.println(<span class="number">0</span>);</span><br><span class="line">            <span class="keyword">else</span> System.out.println(<span class="number">1</span>);</span><br><span class="line">            <span class="keyword">return</span> ;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span>(f)&#123;</span><br><span class="line">            System.out.println(<span class="number">0</span>);</span><br><span class="line">            <span class="keyword">return</span> ;</span><br><span class="line">        &#125;</span><br><span class="line">        fac[<span class="number">0</span>] = BigInteger.valueOf(<span class="number">1</span>);</span><br><span class="line">        <span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">1</span>; i &lt;= n; ++i) fac[i] = fac[i - <span class="number">1</span>].multiply(BigInteger.valueOf(i));</span><br><span class="line">        BigInteger ans = fac[n - <span class="number">2</span>].divide(fac[n - <span class="number">2</span> - sum]);</span><br><span class="line">        <span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; n; ++i)&#123;</span><br><span class="line">            <span class="keyword">if</span>(d[i] == -<span class="number">1</span>) <span class="keyword">continue</span>;</span><br><span class="line">            ans = ans.divide(fac[d[i] - <span class="number">1</span>]);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; n - <span class="number">2</span> - sum; ++i) ans = ans.multiply(BigInteger.valueOf(n - cnt));</span><br><span class="line">        System.out.println(ans);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="Sasha-and-Interesting-Fact-from-Graph-Theory-CodeForces-1113F"><a href="#Sasha-and-Interesting-Fact-from-Graph-Theory-CodeForces-1113F" class="headerlink" title="Sasha and Interesting Fact from Graph Theory CodeForces - 1113F"></a>Sasha and Interesting Fact from Graph Theory CodeForces - 1113F</h2><h3 id="题目描述-1"><a href="#题目描述-1" class="headerlink" title="题目描述"></a>题目描述</h3><p>给定$n$个节点</p>
<p>让你构成树，满足点$a$与点$b$之间的距离为$m$</p>
<p>任意一条边的权值（距离）为$1 \le d \le m$</p>
<p>请问满足条件的树有多少种，对$10^9 + 7$取模</p>
<h3 id="解题思路-1"><a href="#解题思路-1" class="headerlink" title="解题思路"></a>解题思路</h3><p>考虑枚举路径$a \to b$上的点的个数，$2 \le i \le min(m + 1, n)$</p>
<p>因为每条边的权值至少是 $1$</p>
<p>假如有 $i$ 个点，则一定有 $i - 1$ 个边，两点间的距离至少为 $i - 1$</p>
<p>因此$i - 1 \le m$，即$i \le m + 1$</p>
<p>因此当 $a \to b$的路径上有 $i$ 个点时</p>
<p>我们考虑，首先我们需要在总共的$n - 2$个点中（除去$a$与$b$点）有序的选定 $i - 2$ 个点，作为路径上的点</p>
<p>因此确定路径的方案数为$A _ {n - 2} ^ {i - 2}$</p>
<p>然后我们需要确定路径上$i - 1$ 条边的权值，来保证 $a \to b$ 路径距离为 $m$</p>
<p>相当于我们在将$m$个球丢入$i - 1$个桶中，不允许桶为空</p>
<p>很容易想到隔板法，因此方案数为 $C_{m - 1} ^ {i - 1 - 1}$</p>
<p>因此确定这条路径就已经确定了下来，然后我们需要统计其他剩余 $n - i$ 个点的连接方式与距离即可</p>
<p>先确定比较容易理解的距离问题，我们已经确定了 $a \to b$ 的距离为 $m$</p>
<p>剩下的边的权值不会产生任何影响，因此可以在$[1, m]$ 中任意选择，因此方案数为 $m^{n - i}$</p>
<p>这样的话我们就差最后一步没有解决了（场上就差这一步没有想出来）</p>
<p>如何计算 已经确定一条链，剩下节点随便连的树 的方案数呢</p>
<p>我们可以理解为，我们先拿到了以链上节点在不同联通块的 $i$ 棵树</p>
<p>可以假定以它们为根（虽然是无根树），然后将这 $i$ 棵树的根按照链上的顺序，唯一的连接起来</p>
<p>因此，我们很容易想到 Cayley 公式的推广二</p>
<script type="math/tex; mode=display">T_{n, i} = i \cdot n^{n − i - 1}</script><p>因此，最终的答案即为：</p>
<script type="math/tex; mode=display">ans = \sum_{i = 2} ^ {min(m + 1, n)} A _ {n - 2} ^ {i - 2} \cdot T _ {n, i} \cdot C _ {m - 1} ^ {i - 2} \cdot m ^ {n - i}</script><p>写好取模快速幂，将需要用到的 阶乘， 阶乘逆元 等等预处理好</p>
<p>然后按照公式计算一下，这道题就结束了（离F题最近的一次就这么错过了呀）</p>
<h3 id="代码实现-1"><a href="#代码实现-1" class="headerlink" title="代码实现"></a>代码实现</h3><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* ***********************************************</span></span><br><span class="line"><span class="comment">Author        :linxi</span></span><br><span class="line"><span class="comment">Created Time  :2019年02月17日 星期日 02时15分21秒</span></span><br><span class="line"><span class="comment">File Name     :F.cpp</span></span><br><span class="line"><span class="comment">************************************************ */</span></span><br><span class="line"></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;cstdio&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;cstring&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;algorithm&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;string&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;cmath&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;cstdlib&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;vector&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;queue&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;set&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;map&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;bits/stdc++.h&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> sd(n) scanf(<span class="meta-string">"%d"</span>,&amp;n)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> sdd(n,m) scanf(<span class="meta-string">"%d%d"</span>,&amp;n,&amp;m)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> sddd(n,m,k) scanf(<span class="meta-string">"%d%d%d"</span>,&amp;n,&amp;m,&amp;k)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> pd(n) printf(<span class="meta-string">"%d\n"</span>, (n))</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> pdd(n,m) printf(<span class="meta-string">"%d %d"</span>, n, m)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> pld(n) printf(<span class="meta-string">"%lld\n"</span>, n)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> pldd(n,m) printf(<span class="meta-string">"%lld %lld\n"</span>, n, m)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> sld(n) scanf(<span class="meta-string">"%lld"</span>,&amp;n)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> sldd(n,m) scanf(<span class="meta-string">"%lld%lld"</span>,&amp;n,&amp;m)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> slddd(n,m,k) scanf(<span class="meta-string">"%lld%lld%lld"</span>,&amp;n,&amp;m,&amp;k)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> sf(n) scanf(<span class="meta-string">"%lf"</span>,&amp;n)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> sff(n,m) scanf(<span class="meta-string">"%lf%lf"</span>,&amp;n,&amp;m)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> sfff(n,m,k) scanf(<span class="meta-string">"%lf%lf%lf"</span>,&amp;n,&amp;m,&amp;k)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> ss(str) scanf(<span class="meta-string">"%s"</span>,str)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> rep(i,a,n) for (int i=a;i&lt;n;i++)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> per(i,a,n) for (int i=n-1;i&gt;=a;i--)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> mm(a,n) memset(a, n, sizeof(a))</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> debug(x) cout&lt;&lt;#x&lt;&lt;<span class="meta-string">": "</span>&lt;&lt;x&lt;&lt;endl</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> pb push_back</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> all(x) (x).begin(),(x).end()</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> fi first</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> se second</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> mp make_pair</span></span><br><span class="line"><span class="keyword">typedef</span> pair&lt;<span class="keyword">int</span>,<span class="keyword">int</span>&gt; PII;</span><br><span class="line"><span class="keyword">typedef</span> <span class="keyword">long</span> <span class="keyword">long</span> ll;</span><br><span class="line"><span class="keyword">typedef</span> <span class="keyword">unsigned</span> <span class="keyword">long</span> <span class="keyword">long</span> ull;</span><br><span class="line"><span class="keyword">typedef</span> <span class="keyword">long</span> <span class="keyword">double</span> ld;</span><br><span class="line"><span class="keyword">const</span> ll mod = <span class="number">1e9</span> + <span class="number">7</span>;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">double</span> eps = <span class="number">1e-9</span>;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxn = <span class="number">2e6</span> + <span class="number">5</span>;</span><br><span class="line"><span class="comment">//head</span></span><br><span class="line"></span><br><span class="line"><span class="function">ll <span class="title">add</span><span class="params">(ll a, ll b)</span></span>&#123;</span><br><span class="line">    ll ret = (a + b)%mod;</span><br><span class="line">    <span class="keyword">return</span> ret;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function">ll <span class="title">mul</span><span class="params">(ll a, ll b)</span></span>&#123;</span><br><span class="line">    ll ret = (a*b)%mod;</span><br><span class="line">    <span class="keyword">return</span> ret;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function">ll <span class="title">quick</span><span class="params">(ll a, ll b)</span></span>&#123;</span><br><span class="line">    ll ret = <span class="number">1</span>;</span><br><span class="line">    <span class="keyword">while</span>(b)&#123;</span><br><span class="line">        <span class="keyword">if</span>(b&amp;<span class="number">1</span>) ret = mul(ret, a);</span><br><span class="line">        b &gt;&gt;= <span class="number">1</span>;</span><br><span class="line">        a = mul(a, a);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> ret;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function">ll <span class="title">inv</span><span class="params">(ll a)</span></span>&#123;</span><br><span class="line">    ll ret = quick(a, mod - <span class="number">2</span>);</span><br><span class="line">    <span class="keyword">return</span> ret;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">ll f[maxn], rf[maxn];</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">init</span><span class="params">()</span></span>&#123;</span><br><span class="line">    f[<span class="number">0</span>] = rf[<span class="number">0</span>] = <span class="number">1</span>;</span><br><span class="line">    <span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">1</span>; i &lt; maxn; ++i)&#123;</span><br><span class="line">        f[i] = mul(f[i - <span class="number">1</span>], (ll)i);</span><br><span class="line">        rf[i] = inv(f[i]);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function">ll <span class="title">cal</span><span class="params">(ll n, ll k)</span></span>&#123;</span><br><span class="line">    ll ret = mul(f[n], mul(rf[k], rf[n - k]));</span><br><span class="line">    <span class="keyword">return</span> ret;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>&#123;</span><br><span class="line">	<span class="comment">//freopen("in.txt","r",stdin);</span></span><br><span class="line">	<span class="comment">//freopen("out.txt","w",stdout);</span></span><br><span class="line">    init();</span><br><span class="line">    ll n, m, a, b; </span><br><span class="line">    sldd(n, m), sldd(a, b);</span><br><span class="line">    ll ans = <span class="number">0</span>;</span><br><span class="line">    <span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">2</span>; i &lt;= n; ++i)&#123;</span><br><span class="line">        <span class="keyword">if</span>(m &lt; i - <span class="number">1</span>) <span class="keyword">break</span>;</span><br><span class="line">        <span class="keyword">int</span> now = <span class="number">1</span>;</span><br><span class="line">        <span class="keyword">if</span>(i &lt; n)&#123;</span><br><span class="line">            now = mul(now, i);</span><br><span class="line">            now = mul(now, quick(n, n - i - <span class="number">1</span>));</span><br><span class="line">        &#125;</span><br><span class="line">        now = mul(now, cal(n - <span class="number">2</span>, i - <span class="number">2</span>));</span><br><span class="line">        now = mul(now, f[i - <span class="number">2</span>]);</span><br><span class="line">        now = mul(now, quick(m, (n - <span class="number">1</span>) - (i - <span class="number">1</span>)));</span><br><span class="line">        now = mul(now, cal(m - (i - <span class="number">1</span>) + (i - <span class="number">1</span>) - <span class="number">1</span>, (i - <span class="number">1</span>) - <span class="number">1</span>));</span><br><span class="line">        ans = add(ans, now);</span><br><span class="line">    &#125;</span><br><span class="line">    pld(ans);</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

      
    </div>

    

    
    
    

    

    
      
    
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/ACM/" rel="tag"># ACM</a>
          
            <a href="/tags/Math/" rel="tag"># Math</a>
          
            <a href="/tags/Graph-Theory/" rel="tag"># Graph Theory</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/20190214/CodeForces-893-Educational-Codeforces-Round-33/" rel="next" title="CodeForces - 893 Educational Codeforces Round 33">
                <i class="fa fa-chevron-left"></i> CodeForces - 893 Educational Codeforces Round 33
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/20190319/Arithmetic-Device/" rel="prev" title="Arithmetic Device">
                Arithmetic Device <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>


  </div>


          </div>
          

  
    <div class="comments" id="comments">
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope="" itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/images/star.jpg" alt="linxi">
            
              <p class="site-author-name" itemprop="name">linxi</p>
              <p class="site-description motion-element" itemprop="description">stay hungry, stay foolish</p>
          </div>

          
            <nav class="site-state motion-element">
              
                <div class="site-state-item site-state-posts">
                
                  <a href="/archives/">
                
                    <span class="site-state-item-count">15</span>
                    <span class="site-state-item-name">日志</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-categories">
                  <a href="/categories/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">9</span>
                    <span class="site-state-item-name">分类</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-tags">
                  <a href="/tags/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">13</span>
                    <span class="site-state-item-name">标签</span>
                  </a>
                </div>
              
            </nav>
          

          

          

          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-block">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-link"></i>
                Links
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="https://blog.csdn.net/linxilinxilinxi" title="https://blog.csdn.net/linxilinxilinxi" rel="noopener" target="_blank">My CSDN</a>
                  </li>
                
              </ul>
            </div>
          

          
            
          
          

        </div>
      </div>

      
      <!--noindex-->
        <div class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
            
            
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#Cayley-公式"><span class="nav-number">1.</span> <span class="nav-text">Cayley 公式</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#公式内容"><span class="nav-number">1.1.</span> <span class="nav-text">公式内容</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#解决的问题"><span class="nav-number">1.2.</span> <span class="nav-text">解决的问题</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#公式证明方式"><span class="nav-number">1.3.</span> <span class="nav-text">公式证明方式</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#公式的推广"><span class="nav-number">1.4.</span> <span class="nav-text">公式的推广</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#限制特定节点的度的树的计数"><span class="nav-number">1.4.1.</span> <span class="nav-text">限制特定节点的度的树的计数</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#n-个节点-k-棵树的森林计数问题"><span class="nav-number">1.4.2.</span> <span class="nav-text">n 个节点 k 棵树的森林计数问题</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Prufer-序列"><span class="nav-number">2.</span> <span class="nav-text">Prüfer 序列</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#序列定义"><span class="nav-number">2.1.</span> <span class="nav-text">序列定义</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#序列性质"><span class="nav-number">2.2.</span> <span class="nav-text">序列性质</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#证明-Cayley公式"><span class="nav-number">2.3.</span> <span class="nav-text">证明 Cayley公式</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Prufer编码实例"><span class="nav-number">2.4.</span> <span class="nav-text">Prüfer编码实例</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#由一棵树得到唯一的-Prufer-Sequence"><span class="nav-number">2.4.1.</span> <span class="nav-text">由一棵树得到唯一的 Prüfer Sequence</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#由一个-Prufer-Sequence-得到一棵树"><span class="nav-number">2.4.2.</span> <span class="nav-text">由一个 Prüfer Sequence 得到一棵树</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#相关例题"><span class="nav-number">3.</span> <span class="nav-text">相关例题</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#BZOJ-1005-HNOI2008-明明的烦恼"><span class="nav-number">3.1.</span> <span class="nav-text">BZOJ 1005 [HNOI2008] 明明的烦恼</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#题目描述"><span class="nav-number">3.1.1.</span> <span class="nav-text">题目描述</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#解题思路"><span class="nav-number">3.1.2.</span> <span class="nav-text">解题思路</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#代码实现"><span class="nav-number">3.1.3.</span> <span class="nav-text">代码实现</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Sasha-and-Interesting-Fact-from-Graph-Theory-CodeForces-1113F"><span class="nav-number">3.2.</span> <span class="nav-text">Sasha and Interesting Fact from Graph Theory CodeForces - 1113F</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#题目描述-1"><span class="nav-number">3.2.1.</span> <span class="nav-text">题目描述</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#解题思路-1"><span class="nav-number">3.2.2.</span> <span class="nav-text">解题思路</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#代码实现-1"><span class="nav-number">3.2.3.</span> <span class="nav-text">代码实现</span></a></li></ol></li></ol></li></ol></div>
            

          </div>
        </div>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2019 – <span itemprop="copyrightYear">2020</span>
  <span class="with-love" id="animate">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">linxi</span>

  

  
</div>


  <div class="powered-by">由 <a href="https://hexo.io" class="theme-link" rel="noopener" target="_blank">Hexo</a> 强力驱动 v3.8.0</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 – <a href="https://theme-next.org" class="theme-link" rel="noopener" target="_blank">NexT.Pisces</a> v7.0.0</div>





<div class="theme-info">
  <div class="powered-by"></div>
  <span class="post-count">全站共 65.5k 字</span>
</div>

        








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

    

    
  </div>

  

<script>
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>














  
    
    
  
  <script color="25,202,173" opacity="0.8" zindex="-1" count="200" src="/lib/canvas-nest/canvas-nest.min.js"></script>













  
  <script src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>


  


  <script src="/js/src/utils.js?v=7.0.0"></script>

  <script src="/js/src/motion.js?v=7.0.0"></script>



  
  


  <script src="/js/src/affix.js?v=7.0.0"></script>

  <script src="/js/src/schemes/pisces.js?v=7.0.0"></script>



  
  <script src="/js/src/scrollspy.js?v=7.0.0"></script>
<script src="/js/src/post-details.js?v=7.0.0"></script>



  


  <script src="/js/src/bootstrap.js?v=7.0.0"></script>



  
  

<script src="//cdn1.lncld.net/static/js/3.11.1/av-min.js"></script>



<script src="//unpkg.com/valine/dist/Valine.min.js"></script>

<script>
  var GUEST = ['nick', 'mail', 'link'];
  var guest = 'nick,mail,link';
  guest = guest.split(',').filter(function(item) {
    return GUEST.indexOf(item) > -1;
  });
  new Valine({
    el: '#comments',
    verify: false,
    notify: false,
    appId: 'LwzdQrGG81bUwkUkAfdPexj1-gzGzoHsz',
    appKey: 'akTaTqH7XeeKc6CPRfB7vbDl',
    placeholder: 'Just go go',
    avatar: 'mm',
    meta: guest,
    pageSize: '10' || 10,
    visitor: false
  });
</script>




  


  
  <script>
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url).replace(/\/{2,}/g, '/');
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x"></i></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x"></i></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  
  
  <script>
    
    function addCount(Counter) {
      var $visitors = $('.leancloud_visitors');
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();

      Counter('get', '/classes/Counter', { where: JSON.stringify({ url }) })
        .done(function({ results }) {
          if (results.length > 0) {
            var counter = results[0];
            
            Counter('put', '/classes/Counter/' + counter.objectId, JSON.stringify({ time: { '__op': 'Increment', 'amount': 1 } }))
            
              .done(function() {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.time + 1);
              })
            
              .fail(function ({ responseJSON }) {
                console.log(`Failed to save Visitor num, with error message: ${responseJSON.error}`);
              })
          } else {
            
              Counter('post', '/classes/Counter', JSON.stringify({ title: title, url: url, time: 1 }))
                .done(function() {
                  var $element = $(document.getElementById(url));
                  $element.find('.leancloud-visitors-count').text(1);
                })
                .fail(function() {
                  console.log('Failed to create');
                });
            
          }
        })
        .fail(function ({ responseJSON }) {
          console.log(`LeanCloud Counter Error: ${responseJSON.code} ${responseJSON.error}`);
        });
    }
    

    $(function() {
      $.get('https://app-router.leancloud.cn/2/route?appId=' + 'LwzdQrGG81bUwkUkAfdPexj1-gzGzoHsz')
        .done(function({ api_server }) {
          var Counter = function(method, url, data) {
            return $.ajax({
              method: method,
              url: 'https://' + api_server + '/1.1' + url,
              headers: {
                'X-LC-Id': 'LwzdQrGG81bUwkUkAfdPexj1-gzGzoHsz',
                'X-LC-Key': 'akTaTqH7XeeKc6CPRfB7vbDl',
                'Content-Type': 'application/json',
              },
              data: data
            });
          };
          
            addCount(Counter);
          
        });
    });
  </script>



  

  
  

  
  

  
    
      <script type="text/x-mathjax-config">
  

  MathJax.Hub.Config({
    tex2jax: {
      inlineMath: [ ['$','$'], ["\\(","\\)"] ],
      processEscapes: true,
      skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
    },
    TeX: {
      
      equationNumbers: {
        autoNumber: "AMS"
      }
    }
  });
</script>

<script type="text/x-mathjax-config">
  MathJax.Hub.Queue(function() {
    var all = MathJax.Hub.getAllJax(), i;
      for (i = 0; i < all.length; i += 1) {
        all[i].SourceElement().parentNode.className += ' has-jax';
      }
  });
</script>
<script src="//cdn.jsdelivr.net/npm/mathjax@2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

<style>
.MathJax_Display {
  overflow: auto hidden;
}
</style>

    
  


  

  

  

  

  

  

  

  

  

  

</body>
</html>

<!-- 页面点击小红心 -->
<script type="text/javascript" src="/js/src/clicklove.js"></script>

